package thread;

public class SyncDemo3 {
    public static void main(String[] args) {
        Foo f1 = new Foo();
        Foo f2 = new Foo();

        Thread t1 = new Thread(){
          public void run(){
              f1.doSomething();
          }
        };
       Thread t2 = new Thread(){
         public void run(){
             f2.doSomething();
         }
       };
       t1.start();
       t2.start();
    }
}
class Foo {
    //public synchronized static void doSomething(){
    public static void doSomething() {
        synchronized (Foo.class) {
            Thread t = Thread.currentThread();
            System.out.println(t.getName() + ":正在执行dosome方法...");
            try {
                Thread.sleep(4000);
            } catch (InterruptedException e) {
            }
            System.out.println(t.getName() + ":执行dosome方法完毕!");
        }
    }
}